package com.cragon.factory;

import com.cragon.dao.UserDao;
import com.cragon.handler.QueryInvocationHandler;

import java.lang.reflect.Proxy;

/**
 * @Description: TODO
 * @Author: ZHOUHAILONG
 * @Date: 2021年03月01日 19:45
 */
public class LubanFactory {
	public static Object getMapper(Class clazz) {
		Class[] clazzes = new Class[]{clazz};
		QueryInvocationHandler handler = new QueryInvocationHandler();
		// 实现JDK动态代理
		Object o = Proxy.newProxyInstance(LubanFactory.class.getClassLoader(), clazzes, handler);
		return o;
	}

	public static void main(String[] args) {
		UserDao userDao = (UserDao) LubanFactory.getMapper(UserDao.class);
		userDao.query();
		userDao.update();
	}
}
